﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Net.Mail;
using System.Net;


namespace CMD_WEB
{
    public partial class Notificacion : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string email="", unidSolicitud="", msgs="", msgAsunto="";
            email = Request.Params["email"].ToString();
            unidSolicitud = Request.Params["unidSolicitud"].ToString();
            msgs = Request.Params["msgs"].ToString();
            msgAsunto = Request.Params["msgAsunto"].ToString();
            if (email == "" || unidSolicitud == "" || msgs == "" || msgAsunto=="")
            {
                //string mensaje="faltan datos";
                return;
            }
            else
            { 
                EnviaNotificacion(email,unidSolicitud,msgs, msgAsunto);
                Response.Write("<script language='javascript'>window.close ();</script>");
            }
        }
        public static void EnviaNotificacion(string email, string unidSolicitud, string msgs, string msgAsunto)
        {
            string[] a;
            a = email.Split(';');
            MailMessage msg = new MailMessage();

            for (int x = 0; x < a.Length; x++)
            {
                msg.To.Add(new MailAddress(a[x]));
            }

           
            //string fromemail = System.Configuration.ConfigurationManager.AppSettings["FromEmail"];
            msg.From = new MailAddress("beliulsa@gmail.com");
            msg.Subject = msgAsunto;
            msg.Body = msgs;
            SmtpClient clienteSmtp = new SmtpClient("secure.smtp.pmi", 25);
            //clienteSmtp.Credentials = new NetworkCredential("ing.cisnecar@gmail.com", "mono2086");
            //clienteSmtp.EnableSsl = true;
            try
            {
                clienteSmtp.Send(msg);
                
            }

            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }

        }
    }
}